package main

import (
	// "net/http"
	// "encoding/json"
	// "strconv"
	"time"
	// "github.com/dgrijalva/jwt-go"
	// "github.com/labstack/echo"
	"gopkg.in/mgo.v2/bson"
	// "github.com/jinzhu/gorm"
	"oxy_server/module/log"
	"oxy_server/model"
	// "golang.org/x/crypto/bcrypt"
)

type (
	product struct {
		ID bson.ObjectId `json:"_id" bson:"_id"`
		LargeCargoNumber 	string `json:"largecargonumber" bson:"largecargonumber"`
		FactoryNumber 		string `json:"factorynumber" bson:"factorynumber"`
		SupplierName 		string `json:"suppliername" bson:"suppliername"`
		StyleName 			string `json:"stylename" bson:"stylename"`
		Picture 			string `json:"picture" bson:"picture"`
		Gender 				string `json:"gender" bson:"gender"`
		ProductCategory 	string `json:"productcategory" bson:"productcategory"`
		ProductKind 		string `json:"productkind" bson:"productkind"`
		Season		 		string `json:"season" bson:"season"`
		Year		 		string `json:"year" bson:"year"`
		Color		 		string `json:"color" bson:"color"`
		Cost		 		string `json:"cost" bson:"cost"`
		Price		 		string `json:"price" bson:"price"`
		NewMonthPlan	 	string `json:"newmonthplan" bson:"newmonthplan"`
		NewDay			 time.Time `json:"newday" bson:"newday"`
		WhetherMeet			string `json:"whethermeet" bson:"whethermeet"`
		Problem				string `json:"problem" bson:"problem"`
		ProductionTeam		string `json:"productionteam" bson:"productionteam"`
		DesignTeam			string `json:"designteam" bson:"designteam"`
		EditionTeam			string `json:"editionteam" bson:"editionteam"`
		OperationTeam		string `json:"operationteam" bson:"operationteam"`
		PhotographyTeam		string `json:"photographyteam" bson:"photographyteam"`
		PlaneTeam			string `json:"planeteam" bson:"planeteam"`
		WashPic				string `json:"washpic" bson:"washpic"`
		Factorymodelnumber	string `json:"factorymodelnumber" bson:"factorymodelnumber"`
		Person				string `json:"person" bson:"person"`
		IsEdiet 			bool   `json:"isedit" bson:"isedit"`
	}
	sku struct {
		ID bson.ObjectId `json:"_id" bson:"_id"`
		ProductID 					string `json:"productid" bson:"productid"`
		ProductctionGroupID 		string `json:"productctiongroupid" bson:"productctiongroupid"`
		SkuDesc						string `json:"skudesc" bson:"skudesc"`
		SkuCode						string `json:"skucode" bson:"skucode"`
		SkuCount 					string `json:"skucount" bson:"skucount"`
		ActualInbound 				string `json:"actualinbound" bson:"actualinbound"`
		IsEdiet 			bool   `json:"isedit" bson:"isedit"`
		
	}
	skuorder struct {
		ID bson.ObjectId `json:"_id" bson:"_id"`
		ProductID 					string `json:"productid" bson:"productid"`
		ProductctionGroupID 		string `json:"productctiongroupid" bson:"productctiongroupid"`
		SkuCode 					string `json:"skucode" bson:"skucode"`
		SkuDesc 					string `json:"skudesc" bson:"skudesc"`
		ClothingSupplier 			string `json:"clothingsupplier" bson:"clothingsupplier"`
		WatermarkNumber 			string `json:"watermarknumber" bson:"watermarknumber"`
		WatermarkSupplier 			string `json:"watermarksupplier" bson:"watermarksupplier"`
		WatermarkSingleMoney		string `json:"watermarksinglemoney" bson:"watermarksinglemoney"`
		CertificateNumber			string `json:"certificatenumber" bson:"certificatenumber"`
		CertificateSupplier			string `json:"certificatesupplier" bson:"certificatesupplier"`
		CertificateSingleMoney		string `json:"certificatesinglemoney" bson:"certificatesinglemoney"`
		SizemarkNumber 				string `json:"sizemarknumber" bson:"sizemarknumber"`
		SizemarkSupplier 			string `json:"sizemarksupplier" bson:"sizemarksupplier"`
		SizemarkSingleMoney			string `json:"sizemarksinglemoney" bson:"sizemarksinglemoney"`
		Count 						string `json:"count" bson:"count"`
		OrderCount 					string `json:"ordercount" bson:"ordercount"`
		Cost 						string `json:"cost" bson:"cost"`
		OrderTime 					string `json:"ordertime" bson:"ordertime"`
		Time 						string `json:"time" bson:"time"`
		SkuList 					string `json:"skulist" bson:"skulist"`
		Fabriccost					string `json:"fabriccost" bson:"fabriccost"`
		Fabrictotal					string `json:"fabrictotal" bson:"fabrictotal"`
		Feathercost					string `json:"feathercost" bson:"feathercost"`
		Feathertotal				string `json:"feathertotal" bson:"feathertotal"`
		Fabricsupplier				string `json:"fabricsupplier" bson:"fabricsupplier"`
		Feathersupplier				string `json:"feathersupplier" bson:"feathersupplier"`
		Factorymodelnumber			string `json:"factorymodelnumber" bson:"factorymodelnumber"`
		IsEdiet 			bool   `json:"isedit" bson:"isedit"`
		
	}
)


func main() {
	// model.DB().Dbname="OxyCms"
	// model.DB().Document="products"
	// query,count,err:=model.DB().Query(nil,0 ,0 )
	// log.Info("count",count)
	// if err != nil {
	// 	log.Error("查询出错",err)
	// }
	// ps:=[]product{}
	// query.All(&ps)
	// for key,e := range ps {
	// 	log.Info("key",key)
	// 	log.Info("e",e)
	// 	e.IsEdiet = true

	// 	err = model.DB().Update(bson.M{"_id":e.ID} , e)
	// 	if err != nil{
	// 		log.Error("插入失败",err)
	// 		return
	// 	}
	// }
	// log.Info("product success")
	model.DB().Dbname="OxyCms"
	model.DB().Document="sku"
	query,count,err:=model.DB().Query(nil,0 ,0 )
	log.Info("count",count)
	if err != nil {
		log.Error("查询出错",err)
	}
	ps1:=[]sku{}
	query.All(&ps1)
	for key,e := range ps1 {
		log.Info("key",key)
		log.Info("e",e)
		e.IsEdiet = true

		err = model.DB().Update(bson.M{"_id":e.ID} , e)
		if err != nil{
			log.Error("插入失败",err)
			return
		}
	}
	log.Info("product success")
	model.DB().Dbname="OxyCms"
	model.DB().Document="sku_order"
	query1,count,err:=model.DB().Query(nil,0 ,0 )
	log.Info("count",count)
	if err != nil {
		log.Error("查询出错",err)
	}
	ps2:=[]skuorder{}
	query1.All(&ps2)
	for key,e := range ps2 {
		log.Info("key",key)
		log.Info("e",e)
		e.IsEdiet = true

		err = model.DB().Update(bson.M{"_id":e.ID} , e)
		if err != nil{
			log.Error("插入失败",err)
			return
		}
	}
	log.Info("order success")

}